package com.lzb.compressmaster.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

import androidx.annotation.NonNull;

import com.lzb.compressmaster.R;
import com.lzb.compressmaster.basic.BaseSmartDialog;
import com.lzb.compressmaster.databinding.DialogScanIngBinding;

public class ScanIngDialog extends BaseSmartDialog<DialogScanIngBinding> implements View.OnClickListener {

    public ScanIngDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_scan_ing;
    }

    @Override
    protected void initView(View view) {
        Animation animation = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(1000);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setRepeatMode(Animation.RESTART);
        mDataBinding.ivImg.startAnimation(animation);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ivCancel) {
            dismiss();
        } else if (id == R.id.tvConfirm) {
            dismiss();
            if (listener != null) {
                listener.clickConfirm();
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm();
    }
}
